package com.jm.offer.easy;

import com.sun.security.auth.UnixNumericUserPrincipal;

/**
 * @Description https://leetcode-cn.com/problems/he-wei-sde-liang-ge-shu-zi-lcof/
 * @date 2022/4/28 19:20
 */
public class _57和为s的两个数字 {

    public static void main(String[] args) {
        int[] nums = {2,7,11,15};
        int[] ints = twoSum(nums, 9);
        for (int anInt : ints) {
            System.out.println(anInt);
        }
    }

    public static int[] twoSum(int[] nums, int target) {

        if (nums == null){
            return null;
        }
        int[] ret = new int[2];
        int start = 0;
        int end = nums.length - 1;
        while (true) {
            if (nums[start] + nums[end] > target){
                end--;
            }
            if (nums[start] + nums[end] < target){
                start++;
            }
            if (nums[start] + nums[end] == target){
                ret[0] = nums[start];
                ret[1] = nums[end];
                return ret;
            }
        }
    }

}
